<?php

namespace App\Mail;

use App\Models\Record;
use Illuminate\Bus\Queueable;
use Illuminate\Http\Request;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\Mail_log;

class NotifyAdmin extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */

    protected $record;

    public function __construct($record, $request)
    {
        $this->record = $record;
        $data['sender_address'] = env('MAIL_FROM_ADDRESS');
        $data['sender_name'] = env('MAIL_FROM_NAME');
        $data['to'] = config('front.mail');
        $data['subject'] = '51finace';
        $data['data'] = json_encode(['mobile' => $record->mobile, 'time' => $record->create_time]);
        $data['send_time'] = date("Y-m-d H:i:s");
        $data['create_time'] = date("Y-m-d H:i:s");
        $data['create_ip'] = $request->getClientIp();
        Mail_log::create($data);
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        //return $this->view('view.name');
        return $this->view('vendor.mail.notifyadmin')->with(['mobile' => $this->record->mobile, 'time' => $this->record->create_time]);
    }
}
